﻿<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="utf-8"/>
    <meta http-equiv="X-UA-Compatible" content="IE=9; IE=8; IE=7; IE=EDGE">
    <meta http-equiv="X-UA-Compatible" content="IE=EmulateIE7"/>
    <title>jl-boot支付中心</title>
    <script src="https://cdn.bootcss.com/jquery/1.5.1/jquery.min.js"></script>
    <script src="https://cdn.bootcss.com/jquery.qrcode/1.0/jquery.qrcode.min.js"></script>
</head>

<body>

<div>
    <p>请打开微信扫描支付</p>
    <div id="code"></div>
</div>

<script th:inline="javascript">
    let codeUrl_ = [[${codeUrl}]]; //取出二维码地址
    let orderNo_ = [[${orderNo}]]; //取出订单号
    let returnUrl_ = [[${returnUrl}]]; //取出跳转地址
    $('#code').qrcode(codeUrl_);

    // 定会轮询支付状态
    $(function () {
        let timer = setInterval(function () {
            $.ajax({
                url: '/pay/query',
                data: {
                    'orderNo': orderNo_
                },
                success: function (result) {
                    if (result && result.platformStatus && result.platformStatus === 'SUCCESS') {
                        clearTimeout(timer);
                        location.href = returnUrl_ + '?orderNo=' + orderNo_
                    }
                },
                error: function (result) {
                    console.log(result)
                }
            })
        }, 2000)
    })
</script>
</body>

</html>